/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package hibernate;

import controller.MySQL;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.AnnotationConfiguration;

/**
 * Hibernate Utility class with a convenient method to get Session Factory
 * object.
 *
 * @author Felipe
 */
public class HibernateUtil {

    private static SessionFactory sessionFactory = null;
    
    public static void setConnectionProperties(String pConnectionURL, String pUser, String pPassword) {
        try {
            AnnotationConfiguration config = new AnnotationConfiguration().configure();
            config.setProperty("hibernate.connection.url", pConnectionURL);
            config.setProperty("hibernate.connection.username", pUser);
            config.setProperty("hibernate.connection.password", pPassword);
            sessionFactory = config.buildSessionFactory();
            sessionFactory.getCurrentSession().beginTransaction();
        } catch (Exception e) { 
            MySQL.handleException(e);
        }
    }
    
    public static SessionFactory getSessionFactory() {
        return sessionFactory;
    }  
        
}